<%= dropdown do %>
  <%= dropdown_toggle class: 'btn-light dropdown-toggle' do %>
    <span class="text-muted font-weight-normal mr-1">
      <%= Spree.t(:show) %>
    </span>
    <% if product_filter_status_dropdown_value == Spree.t('admin.products.all_statuses') && product_filter_stock_dropdown_value == Spree.t('admin.products.any_stock') %>
      <%= Spree.t(:all_products) %>
    <% else %>
      <%= product_filter_status_dropdown_value if product_filter_status_dropdown_value != Spree.t('admin.products.all_statuses') %>
      <% if product_filter_status_dropdown_value != Spree.t('admin.products.all_statuses') && product_filter_stock_dropdown_value != Spree.t('admin.products.any_stock') %>
        and
      <% end %>
      <%= product_filter_stock_dropdown_value if product_filter_stock_dropdown_value != Spree.t('admin.products.any_stock') %>
    <% end %>
  <% end %>
  <%= dropdown_menu do %>
    <h6 class="dropdown-header"><%= Spree.t('admin.products.by_status') %>:</h6>

    <%= active_link_to Spree.t('admin.products.all_statuses'), params.to_unsafe_h.deep_merge({page: nil, q: {status_eq: nil}}), class: 'dropdown-item', active: (params[:q] || {}).values_at(*%w[status_eq in_stock_items out_of_stock_items] ).all?(&:blank?) %>
    <%= link_to Spree.t('admin.products.active'),
      params.to_unsafe_h.deep_merge({page: nil, q: {status_eq: :active}}),
      class: "dropdown-item #{'active' if params[:q][:status_eq] == 'active'}" %>
    <%= link_to Spree.t('admin.products.draft'),
      params.to_unsafe_h.deep_merge({page: nil, q: {status_eq: :draft}}),
      class: "dropdown-item #{'active' if params[:q][:status_eq] == 'draft'}" %>
    <%= link_to Spree.t('admin.products.archived'),
      params.to_unsafe_h.deep_merge({page: nil, q: {status_eq: :archived}}),
      class: "dropdown-item #{'active' if params[:q][:status_eq] == 'archived'}" %>

    <div class="dropdown-divider"></div>

    <h6 class="dropdown-header"><%= Spree.t('admin.products.by_stock') %>:</h6>

    <%= active_link_to Spree.t('admin.products.any_stock'), params.to_unsafe_h.deep_merge({page: nil, q: {in_stock_items: nil, out_of_stock_items: nil}}), class: 'dropdown-item', active: (params[:q] || {}).values_at(*%w[status_eq in_stock_items out_of_stock_items] ).all?(&:blank?) %>
    <%= link_to Spree.t('admin.products.in_stock'),
        params.to_unsafe_h.deep_merge({page: nil, q: {in_stock_items: '1', out_of_stock_items: nil}}),
        class: "dropdown-item #{'active' if params[:q][:in_stock_items] == '1'}" %>
      <%= link_to Spree.t('admin.products.out_of_stock'),
        params.to_unsafe_h.deep_merge({page: nil, q: {out_of_stock_items: '1', in_stock_items: nil}}),
        class: "dropdown-item #{'active' if params[:q][:out_of_stock_items] == '1'}" %>
  <% end %>
<% end %>
